{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "综合 79.8\n",
      "\n",
      "综合 79.0\n",
      "\n",
      "综合 82.0\n"
     ]
    }
   ],
   "source": [
    "# 1. 打开文件\n",
    "f = open(\"d:\\\\Python程序设计.csv\",\"r\",encoding=\"utf-8\")\n",
    "f2 = open(\"d:\\\\score.csv\",\"w\",encoding=\"utf-8\")\n",
    "f2.write(\"学号,姓名,综合成绩\\n\");\n",
    "\n",
    "# 2. 读取数据\n",
    "firstline = True\n",
    "for line in f:\n",
    "    # 判断是不是第一行\n",
    "    if firstline:\n",
    "        firstline = False\n",
    "        continue\n",
    "    ls = line.split(\",\")\n",
    "    zonghe = float(ls[2])*0.4 + float(ls[3].strip(\"\\n\"))*0.6\n",
    "    print(\"综合\",zonghe)\n",
    "    f2.write(\"{},{},{:.1f}\\n\".format(ls[0],ls[1],zonghe))\n",
    "\n",
    "# 3. 关闭文件\n",
    "f.close()\n",
    "f2.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
